<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../js/vue.js"></script>

</head>
<body>
    <!-- 准备好一个容器 -->
    <div id="root">
        <h1>学校信息</h1>
        <h2>学校名称：{{name}}</h2>
        <h2>学校地址：{{address}}</h2>
        <hr>
        <h1>学生信息</h1>
        <button @click="addSex">添加一个性别属性，默认值是男</button>
        <h2>学生姓名：{{student.name}}</h2>
        <h2>学生真实年龄: {{student.age.rAge}}</h2>
        <h2>学生宣传年龄: {{student.age.sAge}}</h2>
        <h2 v-if="student.sex">学生性别: {{student.sex}}</h2>
        <h2>朋友们</h2>
        <ul>
            <li v-for="(f,index) in student.friends" :key="index">{{f.name}}-{{f.age}}</li>
        </ul>
    </div>

</body>
    <script type="text/javascript">
        const vm = new Vue({
            el:'#root',
            data:{
                name:'尚硅谷',
                address:'西安',
                student:{
                    name:'tom',
                    age:{
                        rAge:58,
                        sAge:18
                    },
                    friends:[
                        {name:'cat',age:48},
                        {name:'lina',age:38}
                    ]
                }
            },
            methods: {
                addSex(){
                    // Vue.set(this.student,'sex','男')
                    this.$set(this.student,'sex','男')
                }
            },
        })       

    </script>

</html>